package com.golden.management.util;

import java.util.Date;

public class QueryPageUtil  {
	
	// 判断是否分页
    private boolean isPage;

    // 当前页数
    private int pageNO;
    
    // 每页显示数量
    private int pageRows;
    
    // 排序字段
 	private String orderByClause;
 	
 	// 排序方向
 	private String sort;
 	
 	// 需要显示的记录数
    private int top;
    
    private String startTimeStamp; //开始时间
    
    private String endTimeStamp;	//结束时间


	public String getOrderByClause() {
		return orderByClause;
	}

	public int getPageNO() {
        return pageNO;
    }

	public int getPageRows() {
        return pageRows;
    }

	public String getSort() {
		if (sort == null || sort.length() == 0) sort = "desc";
		return sort;
	}
    
    /**
 	 * 用于数据库分页查询时,计算起始位置
 	 * @return
 	 */
 	public int getStart() {
 		if (pageNO < 1) pageNO = 1;
 		return (pageNO - 1) * pageRows  ;
 	}
    
    public int getTop() {
        return top;
    }
    

    /**
     * 初始化数据
     * @param pageNO
     * @param pageRows
     * @param order
     * @param sort
     */
    public void initpage(Integer pageNO, int pageRows, String order, String sort) {
    	if (pageNO == null) pageNO = 1;
 		this.pageNO = pageNO;
 		this.pageRows = pageRows;
 		this.orderByClause = order;
 		this.sort = sort;
 	}

    public boolean isPage() {
        return isPage;
    }

    public void setOrderByClause(String orderByClause) {
		this.orderByClause = orderByClause;
	}

    public void setPage(boolean isPage) {
        this.isPage = isPage;
    }

    public void setPageNO(int pageNO) {
        this.pageNO = pageNO;
    }

    public void setPageRows(int pageRows) {
        this.pageRows = pageRows;
    }

    public void setSort(String sort) {
		this.sort = sort;
	}

    public void setTop(int top) {
        this.top = top;
    }

	public Date getStartTime() {
		return new Date(Long.parseLong(startTimeStamp));
	}

	public void setStartTimeStamp(String startTimeStamp) {
		this.startTimeStamp = startTimeStamp;
	}

	public Date getEndTime() {
		return new Date((Long.parseLong(endTimeStamp) + (24 * 60 * 60 * 1000)));
	}

	public void setEndTimeStamp(String endTimeStamp) {
		this.endTimeStamp = endTimeStamp;
	}
	
}
